package com.yuexunit.operationman.nbsy.module.plant.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.plant.bean.MaterialBean;
import com.yuexunit.operationman.nbsy.module.plant.model.impl.MaterialModel;
import com.yuexunit.operationman.nbsy.module.plant.presenter.IMaterialPresenter;
import com.yuexunit.operationman.nbsy.module.plant.presenter.impl.MaterialPresenter;
import com.yuexunit.operationman.nbsy.module.plant.ui.view.IMaterialView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/7/10 0010.
 */

public class Act_Plant_Roll extends KJActivity implements IMaterialView{
    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.usr_head)
    ImageView usrHead;
    @Bind(R.id.usr_name)
    TextView usrName;
    @Bind(R.id.usr_age)
    TextView usrAge;
    @Bind(R.id.usr_gender)
    TextView usrGender;
    @Bind(R.id.ops_date)
    TextView opsDate;
    @Bind(R.id.hisPatientNo)
    TextView hisPatientNo;
    @Bind(R.id.position)
    TextView position;
    @Bind(R.id.scrub_nurse)
    TextView scrubNurse;
    @Bind(R.id.recipe_date)
    TextView recipeDate;
    @Bind(R.id.circulating_nurse)
    TextView circulatingNurse;
    @Bind(R.id.surgical_doctor)
    TextView surgicalDoctor;
    @Bind(R.id.follow_people)
    TextView followPeople;
    @Bind(R.id.collator)
    TextView collator;
    @Bind(R.id.title_01)
    TextView title01;

    IMaterialPresenter presenter;
    String interType;
    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_plant_roll);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        interType = AppConfig.INTERTYPE;
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new MaterialPresenter(this,new MaterialModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        params.put("interType", interType);
        presenter.getMaterialDate(params);
    }

    private void setTitle()
    {
        if(interType.equals("1")){
            titlebarTvTitle.setText("植入性材料使用登记表");
            title01.setText("植入性材料使用登记表");
        }else{
            titlebarTvTitle.setText("材料使用前告知同意书");
            title01.setText("材料使用登记表");
        }
    }


    @OnClick({R.id.titlebar_img_back, R.id.plan_register, R.id.other, R.id.preview})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.plan_register:
                startActivity(new Intent(aty, Act_Plant_Register.class));
                break;
            case R.id.other:
                startActivity(new Intent(aty, Act_Plant_Other.class));
                break;
            case R.id.preview:
                startActivity(new Intent(aty, Act_Plant_Preview.class));
                break;
        }
    }

    @Override
    public void getMaterialDate(MaterialBean materialBean) {
        if(materialBean.getCode() == 200)
        {
            AppConfig.MATERIALBEAN =materialBean;
            usrName.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getPatientName());
            usrAge.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getPatientAge()+"岁");
            if(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getPatientSex().equals("1")) {
                usrGender.setText("男");
            }else if(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getPatientSex().equals("2"))
            {
                usrGender.setText("女");
            }
            else {
                usrGender.setText("不详");
            }
            opsDate.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getOperationTimeStr());
            hisPatientNo.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getInHospitalNo());
            position.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getDepartmentName());
            scrubNurse.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getHandNurse());
            recipeDate.setText("手术名称:"+AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getOperationName());
            circulatingNurse.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getCircuitNurse());
            surgicalDoctor.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getOperationDoctor());
            followPeople.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getAttendantMan());
            collator.setText(AppConfig.MATERIALBEAN.getObject().getImplantMaterial().getCheckMan());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
